# import psutil
# import matplotlib.pyplot as plt
# from matplotlib.animation import FuncAnimation

# fig, ax = plt.subplots()
# x_data, y_data = [], []
# line, = ax.plot([], [], lw=2)

# def init():
#     ax.set_xlim(0, 100)
#     ax.set_ylim(0, 100)
#     return line,

# def update(frame):
#     x_data.append(frame)
#     y_data.append(psutil.cpu_percent())
#     line.set_data(x_data, y_data)
#     return line,

# ani = FuncAnimation(fig, update, frames=range(100), init_func=init, blit=True)
# plt.show()

import os
import platform
import psutil

def get_cpu_score():
    # 获取 CPU 使用率
    cpu_usage = psutil.cpu_percent(interval=1)

    # 获取 CPU 核心数
    cpu_cores = psutil.cpu_count(logical=False) or psutil.cpu_count(logical=True)

    # 获取 CPU 架构信息
    cpu_architecture = platform.architecture()[0]

    # 获取 CPU 频率（仅适用于Linux系统）
    if platform.system() == 'Linux':
        with open('/proc/cpuinfo', 'r') as f:
            cpu_info = f.read()
            cpu_frequency = [float(line.split(":")[1]) for line in cpu_info.splitlines() if 'cpu MHz' in line][0]
    else:
        cpu_frequency = None

    # 计算 CPU 性能评分
    cpu_score = min(100, int(cpu_usage) + int(cpu_cores) * 10)
    
    if cpu_frequency:
        # 如果能获取到频率信息，考虑频率对性能的影响
        cpu_score += min(10, int((cpu_frequency - 2000) / 100))

    return cpu_score

if __name__ == "__main__":
    cpu_score = get_cpu_score()
    print(f"CPU 性能评分: {cpu_score}")

